#ifndef COURSE_MANAGER_H
#define COURSE_MANAGER_H

#include <string>
#include <vector>
#include <optional>

class Database;

struct Student {
    int id;
    int user_id;
    std::string student_id;
    std::string name;
    std::string gender;
    std::string class_name;
    std::string email;
    std::string phone;
};

struct Course {
    int id;
    std::string course_code;
    std::string course_name;
    int teacher_id;
    std::string teacher_name;
    std::string description;
    int credits;
    int max_students;
    int current_students;
    std::string semester;
    std::string classroom;
    std::string schedule;
    std::string status;
};

struct Teacher {
    int id;
    int user_id;
    std::string teacher_id;
    std::string name;
    std::string department;
    std::string email;
    std::string phone;
};

struct CourseSelection {
    int id;
    int student_id;
    int course_id;
    std::string student_name;
    std::string course_name;
    std::string selection_time;
    std::string status;
};

class CourseManager {
public:
    explicit CourseManager(Database* db);
    ~CourseManager();

    // 课程相关
    std::vector<Course> getAllCourses();
    std::optional<Course> getCourseById(int courseId);
    bool courseExists(int courseId);

    // 学生相关
    std::optional<Student> getStudentByUserId(int userId);
    std::vector<Course> getStudentCourses(int studentId);
    std::vector<Student> getAllStudents();

    // 教师相关
    std::optional<Teacher> getTeacherByUserId(int userId);
    std::vector<Teacher> getAllTeachers();
    std::vector<Course> getTeacherCourses(int teacherId);

    // 选课相关
    bool selectCourse(int studentId, int courseId);
    bool dropCourse(int studentId, int courseId);
    bool hasStudentSelectedCourse(int studentId, int courseId);
    bool isCourseAvailable(int courseId);

    // 管理员功能
    std::vector<CourseSelection> getAllCourseSelections();
    std::vector<CourseSelection> getCourseSelectionsByCourseId(int courseId);

private:
    Database* db_;
};

#endif // COURSE_MANAGER_H
